package com.jxb.stringprocess;

/**
 * 	123
 *   19
 */
public class AddStrings_415 {

    public static void main(String[] args) {
        System.out.println(addStrings("121","22"));
    }

    public static String addStrings(String num1, String num2) {
        StringBuilder sb = new StringBuilder();
        //定义进位
        int array = 0;
        //进行倒序遍历进行计算
        for (int i = num1.length()-1, j = num2.length()-1;i>=0 || j>=0 || array == 1;i--,j--) {
            //- '0'是为了将char变成int类型
            int x = i<0 ? 0:num1.charAt(i) - '0';
            int y = j<0 ? 0:num2.charAt(j) - '0';
            sb.append((x+y+array)%10);
            array = (x+y+array)/10;
        }
        return sb.reverse().toString();
    }

}
